package org.mozhu.mboot.admin.system.auth.service;

import org.mozhu.mboot.admin.system.privilege.entity.Permission;
import org.mozhu.mboot.admin.system.privilege.entity.Role;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service("defaultAuthorityService")
public class DefaultAuthorityService extends AbstractAuthorityService implements AuthorityService {

    @Override
    public Set<String> findStringRoles(Long userId) {
        List<Role> defaultRoles = roleService.findDefaultRoles();
        return stringRoles(defaultRoles);
    }

    @Override
    public Set<String> findStringPermissions(Long userId) {
        List<Role> defaultRoles = roleService.findDefaultRoles();
        Set<Long> permissionIds = rolesToPermissionIds(defaultRoles);
        List<Permission> permissions = permissionService.findAvailablePermissions(permissionIds);
        permissions.addAll(permissionService.findDefaultPermissions());
        return stringPermissions(permissions);
    }

}
